package client;

import static com.google.gwt.user.client.Window.Location.getParameter;
import client.persistance.Adminko;
import client.persistance.AdminkoAsync;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;

public class PlanEntryPoing implements EntryPoint {
	private AdminkoAsync serv = Adminko.App.getInstance();

	public void onModuleLoad() {
		String encodedPath = getParameter("id");
		serv.getURLFromUniquePath(encodedPath, new AsyncCallback<String>() {
			@Override
			public void onSuccess(String path) {
				String[] pathElements = path.split(";;");
				String email = pathElements[0];
				Long planId = new Long(pathElements[1]);

				RootPanel.get().add(new Label("Hi " + email + " from " + planId + " plan ID " + "!"));
			}

			@Override
			public void onFailure(Throwable caught) {
				Window.alert("Can't recognize the path. Please try to scream.");
			}
		});
	}

	public static class PathKeyCl {
		private long planId;
		private String email;

		public PathKeyCl(long planId, String email) {
			this.planId = planId;
			this.email = email;
		}

		public long getPlanId() {
			return planId;
		}

		public String getEmail() {
			return email;
		}
	}
}
